package com.yanqu.road.server.cmd.banquet.party;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.banquet.CrossPartyMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = CrossProtocol.C_CROSS_PARTY_OPEN, desc = "")
public class CrossOpenPartyCmd extends CrossCommand {
    private long userId;
    private int type;
    private String invitationId;
    private String invitationInfo;
    private UserBaseInfo userBaseInfo;
    private String serverListStr;
    private String giftTypeAccept;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BanquetProto.CrossOpenPartyReqMsg req = BanquetProto.CrossOpenPartyReqMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        type = req.getType();
        invitationId = req.getInvitationId();
        invitationInfo = req.getInvitationInfo();
        userBaseInfo = PlayerBasePb.parseToUserBaseInfo(req.getPlayerBaseData());
        serverListStr = req.getServerListStr();
        this.giftTypeAccept = "";
        if (req.hasGiftTypeAccept()) {
            this.giftTypeAccept = req.getGiftTypeAccept();
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        BanquetProto.CrossOpenPartyRespMsg.Builder resp = CrossPartyMgr.openParty(serverId, userId, userBaseInfo, type, invitationId, invitationInfo, serverListStr, giftTypeAccept);
        YanQuMessage msg = YanQuMessageUtils.buildMessage(GameProtocol.S_CROSS_PARTY_OPEN_RESULT, resp);
        MessageHelper.sendPacket(serverId, userId, msg);
    }

    @Override
    public void sendData() {

    }
}
